home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / gnulib / libsrc98.zoo / exec.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-05  |  1.7 KB  |  76 lines

  1. /*
  2.  * exec.c:: various execXX emulations. If we're in a child that has been
  3.  * forked, then we restore our parent's data area and shrink the
  4.  * fork information block to the minimum. If we're not in any child, then
  5.  * we just wing it (we probably should shrink the text+data+bss block to
  6.  * give more room, but that would be rather difficult to do properly).
  7.  *
  8.  * the real work is done in spawnve.c.
  9.  */
  10.  
  11. #include <compiler.h>
  12. #include <osbind.h>
  13. #include <basepage.h>
  14. #include <process.h>
  15. #include <file.h>
  16. #include <stdarg.h>
  17. #include <unistd.h>
  18.  
  19. extern int _x_Bit_set_in_stat; /* in stat.c */
  20.  
  21. int
  22. execve(path, argv, envp)
  23.     const char *path;
  24.     char * const *argv;
  25.     char * const *envp;
  26. {
  27.     int savex = _x_Bit_set_in_stat;
  28.  
  29. /* check to make sure that the file is executable. alas, this is not
  30.    foolproof, since .g and .sh files are marked as executable even though
  31.    they're not, really.
  32.  */
  33.     _x_Bit_set_in_stat = 1;
  34.     if (access(path, X_OK)) {
  35.             _x_Bit_set_in_stat = savex;
  36.         return -1;
  37.     }
  38.         _x_Bit_set_in_stat = savex;
  39. /*
  40.  * the call to spawnve shouldn't return unless there is an error
  41.  */
  42.     return spawnve(P_OVERLAY, path, argv, envp);
  43. }
  44.  
  45. int
  46. execv(path, argv)
  47.     const char *path;
  48.     char * const *argv;
  49. {
  50.     return execve(path, argv, (char **)0);
  51. }
  52.  
  53. int
  54. execvp(name, argv)
  55.     const char *name;
  56.     char * const *argv;
  57. {
  58.     /* note: we cannot check x bit here as we dont know the full path.
  59.      * we flag spawnvp to do this by passing it -ve mode
  60.      */
  61.     return spawnvp(-P_OVERLAY, name, argv);
  62. }
  63.  
  64. #ifdef __STDC__
  65. int execl(const char *path, ...)
  66. #else
  67. int execl(path)
  68.     char    *path;
  69. #endif
  70. {
  71.     va_list args;
  72.  
  73.     va_start(args, path);
  74.     return execve(path, (char **)args, (char **)0);
  75. }
  76.